package concert;

import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.*;
import org.springframework.stereotype.Component;

/**
 * Created by jack on 18/5/29.
 * Audience类：观看演出的切面
 */

@Component
@Aspect
public class Audience {
    /*
    @Before("execution(* concert.Performance.perform(..))")
    public void silenceCellPhones(){
        System.out.println("Silence cell phones");
    }
    @Before("execution(* concert.Performance.perform(..))")
    public void takeSeats(){
        System.out.println("taking seats");
    }
    @AfterReturning("execution(* concert.Performance.perform(..))")
    public void applause(){
        System.out.println("CLAP CLAP CLAP");
    }
    @AfterThrowing("execution(* concert.Performance.perform(..))")
    public void demandRefund(){
        System.out.println("Demanding a refund");
    }
    */

    /*写法二：在上述的写法中，频繁使用了一个切点表达式*/
    @Pointcut("execution(* concert.Performance.perform(..))")
    public void performance(){}

    @Before("performance()")
    public void silenceCellPhones(){
        System.out.println("Silence cell phones");
    }
    @Before("performance()")
    public void takeSeats(){
        System.out.println("taking seats");
    }
    @AfterReturning("performance()")
    public void applause(){
        System.out.println("CLAP CLAP CLAP");
    }
    @AfterThrowing("performance()")
    public void demandRefund(){
        System.out.println("demand refound");
    }

    /*使用环绕通知*/
    @Around("performance()")
    public void watchPerformace(ProceedingJoinPoint jp){
        try{
            System.out.println("Silence cell phones 1");
            System.out.println("Taking the seats 1");
            jp.proceed();
            System.out.println("CLAP CLAP CLAP 1");
        }catch(Throwable e){
            System.out.println("Demanding a refund 1");
        }
    }


}
